home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / install / g_t_expr.man < prev    next >
Encoding:
Text File  |  1988-10-20  |  47.6 KB  |  1,059 lines

  1.  
  2. File: internals,  Node: Side Effects,  Next: Incdec,  Prev: RTL Declarations,  Up: RTL
  3.  
  4. Side Effect Expressions
  5. =======================
  6.  
  7. The expression codes described so far represent values, not actions.  But
  8. machine instructions never produce values; they are meaningful only for
  9. their side effects on the state of the machine.  Special expression codes
  10. are used to represent side effects.
  11.  
  12. The body of an instruction is always one of these side effect codes; the
  13. codes described above, which represent values, appear only as the operands
  14. of these.
  15.  
  16. `(set LVAL X)'
  17.      Represents the action of storing the value of X into the place
  18.      represented by LVAL.  LVAL must be an expression representing a place
  19.      that can be stored in: `reg' (or `subreg' or `strict_low_part'),
  20.      `mem', `pc' or `cc0'.
  21.  
  22.      If LVAL is a `reg', `subreg' or `mem', it has a machine mode; then X
  23.      must be valid for that mode.
  24.  
  25.      If LVAL is a `reg' whose machine mode is less than the full width of
  26.      the register, then it means that the part of the register specified by
  27.      the machine mode is given the specified value and the rest of the
  28.      register receives an undefined value.  Likewise, if LVAL is a `subreg'
  29.      whose machine mode is narrower than `SImode', the rest of the register
  30.      can be changed in an undefined way.
  31.  
  32.      If LVAL is a `strict_low_part' of a `subreg', then the part of the
  33.      register specified by the machine mode of the `subreg' is given the
  34.      value X and the rest of the register is not changed.
  35.  
  36.      If LVAL is `(cc0)', it has no machine mode, and X may have any mode. 
  37.      This represents a ``test'' or ``compare'' instruction.
  38.  
  39.      If LVAL is `(pc)', we have a jump instruction, and the possibilities
  40.      for X are very limited.  It may be a `label_ref' expression
  41.      (unconditional jump).  It may be an `if_then_else' (conditional jump),
  42.      in which case either the second or the third operand must be `(pc)'
  43.      (for the case which does not jump) and the other of the two must be a
  44.      `label_ref' (for the case which does jump).  X may also be a `mem' or
  45.      `(plus:SI (pc) Y)', where Y may be a `reg' or a `mem'; these unusual
  46.      patterns are used to represent jumps through branch tables.
  47.  
  48. `(return)'
  49.      Represents a return from the current function, on machines where this
  50.      can be done with one instruction, such as Vaxes.  On machines where a
  51.      multi-instruction ``epilogue'' must be executed in order to return
  52.      from the function, returning is done by jumping to a label which
  53.      precedes the epilogue, and the `return' expression code is never used.
  54.  
  55. `(call FUNCTION NARGS)'
  56.      Represents a function call.  FUNCTION is a `mem' expression whose
  57.      address is the address of the function to be called.  NARGS is an
  58.      expression representing the number of words of argument.
  59.  
  60.      Each machine has a standard machine mode which FUNCTION must have. 
  61.      The machine description defines macro `FUNCTION_MODE' to expand into
  62.      the requisite mode name.  The purpose of this mode is to specify what
  63.      kind of addressing is allowed, on machines where the allowed kinds of
  64.      addressing depend on the machine mode being addressed.
  65.  
  66. `(clobber X)'
  67.      Represents the storing or possible storing of an unpredictable,
  68.      undescribed value into X, which must be a `reg' or `mem' expression.
  69.  
  70.      One place this is used is in string instructions that store standard
  71.      values into particular hard registers.  It may not be worth the
  72.      trouble to describe the values that are stored, but it is essential to
  73.      inform the compiler that the registers will be altered, lest it
  74.      attempt to keep data in them across the string instruction.
  75.  
  76.      X may also be null---a null C pointer, no expression at all.  Such a
  77.      `(clobber (null))' expression means that all memory locations must be
  78.      presumed clobbered.
  79.  
  80.      Note that the machine description classifies certain hard registers as
  81.      ``call-clobbered''.  All function call instructions are assumed by
  82.      default to clobber these registers, so there is no need to use
  83.      `clobber' expressions to indicate this fact.  Also, each function call
  84.      is assumed to have the potential to alter any memory location.
  85.  
  86. `(use X)'
  87.      Represents the use of the value of X.  It indicates that the value in
  88.      X at this point in the program is needed, even though it may not be
  89.      apparent why this is so.  Therefore, the compiler will not attempt to
  90.      delete instructions whose only effect is to store a value in X.  X
  91.      must be a `reg' expression.
  92.  
  93. `(parallel [X0 X1 ...])'
  94.      Represents several side effects performed in parallel.  The square
  95.      brackets stand for a vector; the operand of `parallel' is a vector of
  96.      expressions.  X0, X1 and so on are individual side
  97.      effects---expressions of code `set', `call', `return', `clobber' or
  98.      `use'.
  99.  
  100.      ``In parallel'' means that first all the values used in the individual
  101.      side-effects are computed, and second all the actual side-effects are
  102.      performed.  For example,
  103.  
  104.           (parallel [(set (reg:SI 1) (mem:SI (reg:SI 1)))
  105.                      (set (mem:SI (reg:SI 1)) (reg:SI 1))])
  106.  
  107.      says unambiguously that the values of hard register 1 and the memory
  108.      location addressed by it are interchanged.  In both places where
  109.      `(reg:SI 1)' appears as a memory address it refers to the value in
  110.      register 1 *before* the execution of the instruction.
  111.  
  112. `(sequence [INSNS ...])'
  113.      Represents a sequence of insns.  Each of the INSNS that appears in the
  114.      vector is suitable for appearing in the chain of insns, so it must be
  115.      an `insn', `jump_insn', `call_insn', `code_label', `barrier' or `note'.
  116.  
  117.      A `sequence' RTX never appears in an actual insn.  It represents the
  118.      sequence of insns that result from a `define_expand' *before* those
  119.      insns are passed to `emit_insn' to insert them in the chain of insns. 
  120.      When actually inserted, the individual sub-insns are separated out and
  121.      the `sequence' is forgotten.
  122.  
  123. Three expression codes appear in place of a side effect, as the body of an
  124. insn, though strictly speaking they do not describe side effects as such:
  125.  
  126. `(asm_input S)'
  127.      Represents literal assembler code as described by the string S.
  128.  
  129. `(addr_vec:M [LR0 LR1 ...])'
  130.      Represents a table of jump addresses.  The vector elements LR0, etc.,
  131.      are `label_ref' expressions.  The mode M specifies how much space is
  132.      given to each address; normally M would be `Pmode'.
  133.  
  134. `(addr_diff_vec:M BASE [LR0 LR1 ...])'
  135.      Represents a table of jump addresses expressed as offsets from BASE. 
  136.      The vector elements LR0, etc., are `label_ref' expressions and so is
  137.      BASE.  The mode M specifies how much space is given to each
  138.      address-difference.
  139.  
  140. File: internals,  Node: Incdec,  Next: Assembler,  Prev: Side Effects,  Up: RTL
  141.  
  142. Embedded Side-Effects on Addresses
  143. ==================================
  144.  
  145. Four special side-effect expression codes appear as memory addresses.
  146.  
  147. `(pre_dec:M X)'
  148.      Represents the side effect of decrementing X by a standard amount and
  149.      represents also the value that X has after being decremented.  X must
  150.      be a `reg' or `mem', but most machines allow only a `reg'.  M must be
  151.      the machine mode for pointers on the machine in use.  The amount X is
  152.      decremented by is the length in bytes of the machine mode of the
  153.      containing memory reference of which this expression serves as the
  154.      address.  Here is an example of its use:
  155.  
  156.           (mem:DF (pre_dec:SI (reg:SI 39)))
  157.  
  158.      This says to decrement pseudo register 39 by the length of a `DFmode'
  159.      value and use the result to address a `DFmode' value.
  160.  
  161. `(pre_inc:M X)'
  162.      Similar, but specifies incrementing X instead of decrementing it.
  163.  
  164. `(post_dec:M X)'
  165.      Represents the same side effect as `pre_decrement' but a different
  166.      value.  The value represented here is the value X has before being
  167.      decremented.
  168.  
  169. `(post_inc:M X)'
  170.      Similar, but specifies incrementing X instead of decrementing it.
  171.  
  172. These embedded side effect expressions must be used with care.  Instruction
  173. patterns may not use them.  Until the `flow' pass of the compiler, they may
  174. occur only to represent pushes onto the stack.  The `flow' pass finds cases
  175. where registers are incremented or decremented in one instruction and used
  176. as an address shortly before or after; these cases are then transformed to
  177. use pre- or post-increment or -decrement.
  178.  
  179. Explicit popping of the stack could be represented with these embedded side
  180. effect operators, but that would not be safe; the instruction combination
  181. pass could move the popping past pushes, thus changing the meaning of the
  182. code.
  183.  
  184. An instruction that can be represented with an embedded side effect could
  185. also be represented using `parallel' containing an additional `set' to
  186. describe how the address register is altered.  This is not done because
  187. machines that allow these operations at all typically allow them wherever a
  188. memory address is called for.  Describing them as additional parallel
  189. stores would require doubling the number of entries in the machine
  190. description.
  191.  
  192. File: internals,  Node: Assembler,  Next: Insns,  Prev: IncDec,  Up: RTL
  193.  
  194. Assembler Instructions as Expressions
  195. =====================================
  196.  
  197. The RTX code `asm_operands' represents a value produced by a user-specified
  198. assembler instruction.  It is used to represent an `asm' statement with
  199. arguments.  An `asm' statement with a single output operand, like this:
  200.  
  201.      asm ("foo %1,%2,%0" : "a" (outputvar) : "g" (x + y), "di" (*z));
  202.  
  203. is represented using a single `asm_operands' RTX which represents the value
  204. that is stored in `outputvar':
  205.  
  206.      (set RTX-FOR-OUTPUTVAR
  207.           (asm_operands "foo %1,%2,%0" "a" 0
  208.                         [RTX-FOR-ADDITION-RESULT RTX-FOR-*Z]
  209.                         [(asm_input:M1 "g")
  210.                          (asm_input:M2 "di")]))
  211.  
  212. Here the operands of the `asm_operands' RTX are the assembler template
  213. string, the output-operand's constraint, the index-number of the output
  214. operand among the output operands specified, a vector of input operand
  215. RTX's, and a vector of input-operand modes and constraints.  The mode M1 is
  216. the mode of the sum `x+y'; M2 is that of `*z'.
  217.  
  218. When an `asm' statement has multiple output values, its insn has several
  219. such `set' RTX's inside of a `parallel'.  Each `set' contains a
  220. `asm_operands'; all of these share the same assembler template and vectors,
  221. but each contains the constraint for the respective output operand.  They
  222. are also distinguished by the output-operand index number, which is 0, 1,
  223. ... for successive output operands.
  224.  
  225. File: internals,  Node: Insns,  Next: Calls,  Prev: Assembler,  Up: RTL
  226.  
  227. Insns
  228. =====
  229.  
  230. The RTL representation of the code for a function is a doubly-linked chain
  231. of objects called "insns".  Insns are expressions with special codes that
  232. are used for no other purpose.  Some insns are actual instructions; others
  233. represent dispatch tables for `switch' statements; others represent labels
  234. to jump to or various sorts of declarative information.
  235.  
  236. In addition to its own specific data, each insn must have a unique
  237. id-number that distinguishes it from all other insns in the current
  238. function, and chain pointers to the preceding and following insns.  These
  239. three fields occupy the same position in every insn, independent of the
  240. expression code of the insn.  They could be accessed with `XEXP' and
  241. `XINT', but instead three special macros are always used:
  242.  
  243. `INSN_UID (I)'
  244.      Accesses the unique id of insn I.
  245.  
  246. `PREV_INSN (I)'
  247.      Accesses the chain pointer to the insn preceding I.  If I is the first
  248.      insn, this is a null pointer.
  249.  
  250. `NEXT_INSN (I)'
  251.      Accesses the chain pointer to the insn following I.  If I is the last
  252.      insn, this is a null pointer.
  253.  
  254. The `NEXT_INSN' and `PREV_INSN' pointers must always correspond: if I is
  255. not the first insn,
  256.  
  257.      NEXT_INSN (PREV_INSN (INSN)) == INSN
  258.  
  259. is always true.
  260.  
  261. Every insn has one of the following six expression codes:
  262.  
  263. `insn'
  264.      The expression code `insn' is used for instructions that do not jump
  265.      and do not do function calls.  Insns with code `insn' have four
  266.      additional fields beyond the three mandatory ones listed above.  These
  267.      four are described in a table below.
  268.  
  269. `jump_insn'
  270.      The expression code `jump_insn' is used for instructions that may jump
  271.      (or, more generally, may contain `label_ref' expressions). 
  272.      `jump_insn' insns have the same extra fields as `insn' insns, accessed
  273.      in the same way.
  274.  
  275. `call_insn'
  276.      The expression code `call_insn' is used for instructions that may do
  277.      function calls.  It is important to distinguish these instructions
  278.      because they imply that certain registers and memory locations may be
  279.      altered unpredictably.
  280.  
  281.      `call_insn' insns have the same extra fields as `insn' insns, accessed
  282.      in the same way.
  283.  
  284. `code_label'
  285.      A `code_label' insn represents a label that a jump insn can jump to. 
  286.      It contains one special field of data in addition to the three
  287.      standard ones.  It is used to hold the "label number", a number that
  288.      identifies this label uniquely among all the labels in the compilation
  289.      (not just in the current function).  Ultimately, the label is
  290.      represented in the assembler output as an assembler label `LN' where N
  291.      is the label number.
  292.  
  293. `barrier'
  294.      Barriers are placed in the instruction stream after unconditional jump
  295.      instructions to indicate that the jumps are unconditional.  They
  296.      contain no information beyond the three standard fields.
  297.  
  298. `note'
  299.      `note' insns are used to represent additional debugging and
  300.      declarative information.  They contain two nonstandard fields, an
  301.      integer which is accessed with the macro `NOTE_LINE_NUMBER' and a
  302.      string accessed with `NOTE_SOURCE_FILE'.
  303.  
  304.      If `NOTE_LINE_NUMBER' is positive, the note represents the position of
  305.      a source line and `NOTE_SOURCE_FILE' is the source file name that the
  306.      line came from.  These notes control generation of line number data in
  307.      the assembler output.
  308.  
  309.      Otherwise, `NOTE_LINE_NUMBER' is not really a line number but a code
  310.      with one of the following values (and `NOTE_SOURCE_FILE' must contain
  311.      a null pointer):
  312.  
  313.      `NOTE_INSN_DELETED'
  314.           Such a note is completely ignorable.  Some passes of the compiler
  315.           delete insns by altering them into notes of this kind.
  316.  
  317.      `NOTE_INSN_BLOCK_BEG'
  318.      `NOTE_INSN_BLOCK_END'
  319.           These types of notes indicate the position of the beginning and
  320.           end of a level of scoping of variable names.  They control the
  321.           output of debugging information.
  322.  
  323.      `NOTE_INSN_LOOP_BEG'
  324.      `NOTE_INSN_LOOP_END'
  325.           These types of notes indicate the position of the beginning and
  326.           end of a `while' or `for' loop.  They enable the loop optimizer
  327.           to find loops quickly.
  328.  
  329. Here is a table of the extra fields of `insn', `jump_insn' and `call_insn'
  330. insns:
  331.  
  332. `PATTERN (I)'
  333.      An expression for the side effect performed by this insn.
  334.  
  335. `REG_NOTES (I)'
  336.      A list (chain of `expr_list' expressions) giving information about the
  337.      usage of registers in this insn.  This list is set up by the flow
  338.      analysis pass; it is a null pointer until then.
  339.  
  340. `LOG_LINKS (I)'
  341.      A list (chain of `insn_list' expressions) of previous ``related''
  342.      insns: insns which store into registers values that are used for the
  343.      first time in this insn.  (An additional constraint is that neither a
  344.      jump nor a label may come between the related insns).  This list is
  345.      set up by the flow analysis pass; it is a null pointer until then.
  346.  
  347. `INSN_CODE (I)'
  348.      An integer that says which pattern in the machine description matches
  349.      this insn, or -1 if the matching has not yet been attempted.
  350.  
  351.      Such matching is never attempted and this field is not used on an insn
  352.      whose pattern consists of a single `use', `clobber', `asm', `addr_vec'
  353.      or `addr_diff_vec' expression.
  354.  
  355. The `LOG_LINKS' field of an insn is a chain of `insn_list' expressions. 
  356. Each of these has two operands: the first is an insn, and the second is
  357. another `insn_list' expression (the next one in the chain).  The last
  358. `insn_list' in the chain has a null pointer as second operand.  The
  359. significant thing about the chain is which insns appear in it (as first
  360. operands of `insn_list' expressions).  Their order is not significant.
  361.  
  362. The `REG_NOTES' field of an insn is a similar chain but of `expr_list'
  363. expressions instead of `insn_list'.  There are four kinds of register
  364. notes, which are distinguished by the machine mode of the `expr_list',
  365. which a register note is really understood as being an `enum reg_note'. 
  366. The first operand OP of the `expr_list' is data whose meaning depends on
  367. the kind of note.  Here are the four kinds:
  368.  
  369. `REG_DEAD'
  370.      The register OP dies in this insn; that is to say, altering the value
  371.      immediately after this insn would not affect the future behavior of
  372.      the program.
  373.  
  374. `REG_INC'
  375.      The register OP is incremented (or decremented; at this level there is
  376.      no distinction) by an embedded side effect inside this insn.  This
  377.      means it appears in a `POST_INC', `PRE_INC', `POST_DEC' or `PRE_DEC'
  378.      RTX.
  379.  
  380. `REG_EQUIV'
  381.      The register that is set by this insn will be equal to OP at run time,
  382.      and could validly be replaced in all its occurrences by OP. 
  383.      (``Validly'' here refers to the data flow of the program; simple
  384.      replacement may make some insns invalid.)
  385.  
  386.      The value which the insn explicitly copies into the register may look
  387.      different from OP, but they will be equal at run time.
  388.  
  389.      For example, when a constant is loaded into a register that is never
  390.      assigned any other value, this kind of note is used.
  391.  
  392.      When a parameter is copied into a pseudo-register at entry to a
  393.      function, a note of this kind records that the register is equivalent
  394.      to the stack slot where the parameter was passed.  Although in this
  395.      case the register may be set by other insns, it is still valid to
  396.      replace the register by the stack slot throughout the function.
  397.  
  398. `REG_EQUAL'
  399.      The register that is set by this insn will be equal to OP at run time
  400.      at the end of this insn (but not necessarily elsewhere in the function).
  401.  
  402.      The RTX OP is typically an arithmetic expression.  For example, when a
  403.      sequence of insns such as a library call is used to perform an
  404.      arithmetic operation, this kind of note is attached to the insn that
  405.      produces or copies the final value.  It tells the CSE pass how to
  406.      think of that value.
  407.  
  408. `REG_RETVAL'
  409.      This insn copies the value of a library call, and OP is the first insn
  410.      that was generated to set up the arguments for the library call.
  411.  
  412.      Flow analysis uses this note to delete all of a library call whose
  413.      result is dead.
  414.  
  415. `REG_WAS_0'
  416.      The register OP contained zero before this insn.  You can rely on this
  417.      note if it is present; its absence implies nothing.
  418.  
  419. (The only difference between the expression codes `insn_list' and
  420. `expr_list' is that the first operand of an `insn_list' is assumed to be an
  421. insn and is printed in debugging dumps as the insn's unique id; the first
  422. operand of an `expr_list' is printed in the ordinary way as an expression.)
  423.  
  424. File: internals,  Node: Calls,  Next: Sharing,  Prev: Insns,  Up: RTL
  425.  
  426. RTL Representation of Function-Call Insns
  427. =========================================
  428.  
  429. Insns that call subroutines have the RTL expression code `call_insn'. 
  430. These insns must satisfy special rules, and their bodies must use a special
  431. RTL expression code, `call'.
  432.  
  433. A `call' expression has two operands, as follows:
  434.  
  435.      (call NBYTES (mem:FM ADDR))
  436.  
  437. Here NBYTES is an operand that represents the number of bytes of argument
  438. data being passed to the subroutine, FM is a machine mode (which must equal
  439. as the definition of the `FUNCTION_MODE' macro in the machine description)
  440. and ADDR represents the address of the subroutine.
  441.  
  442. For a subroutine that returns no value, the `call' RTX as shown above is
  443. the entire body of the insn.
  444.  
  445. For a subroutine that returns a value whose mode is not `BLKmode', the
  446. value is returned in a hard register.  If this register's number is R, then
  447. the body of the call insn looks like this:
  448.  
  449.      (set (reg:M R)
  450.           (call NBYTES (mem:FM ADDR)))
  451.  
  452. This RTL expression makes it clear (to the optimizer passes) that the
  453. appropriate register receives a useful value in this insn.
  454.  
  455. Immediately after RTL generation, if the value of the subroutine is
  456. actually used, this call insn is always followed closely by an insn which
  457. refers to the register R.  This remains true through all the optimizer
  458. passes until cross jumping occurs.
  459.  
  460. The following insn has one of two forms.  Either it copies the value into a
  461. pseudo-register, like this:
  462.  
  463.      (set (reg:M P) (reg:M R))
  464.  
  465. or (in the case where the calling function will simply return whatever
  466. value the call produced, and no operation is needed to do this):
  467.  
  468.      (use (reg:M R))
  469.  
  470. Between the call insn and this following insn there may intervene only a
  471. stack-adjustment insn (and perhaps some `note' insns).
  472.  
  473. When a subroutine returns a `BLKmode' value, it is handled by passing to
  474. the subroutine the address of a place to store the value.  So the call insn
  475. itself does not ``return'' any value, and it has the same RTL form as a
  476. call that returns nothing.
  477.  
  478. File: internals,  Node: Sharing,  Prev: Calls,  Up: RTL
  479.  
  480. Structure Sharing Assumptions
  481. =============================
  482.  
  483. The compiler assumes that certain kinds of RTL expressions are unique;
  484. there do not exist two distinct objects representing the same value.  In
  485. other cases, it makes an opposite assumption: that no RTL expression object
  486. of a certain kind appears in more than one place in the containing structure.
  487.  
  488. These assumptions refer to a single function; except for the RTL objects
  489. that describe global variables and external functions, no RTL objects are
  490. common to two functions.
  491.  
  492.    * Each pseudo-register has only a single `reg' object to represent it,
  493.      and therefore only a single machine mode.
  494.  
  495.    * For any symbolic label, there is only one `symbol_ref' object
  496.      referring to it.
  497.  
  498.    * There is only one `const_int' expression with value zero, and only one
  499.      with value one.
  500.  
  501.    * There is only one `pc' expression.
  502.  
  503.    * There is only one `cc0' expression.
  504.  
  505.    * There is only one `const_double' expression with mode `SFmode' and
  506.      value zero, and only one with mode `DFmode' and value zero.
  507.  
  508.    * No `label_ref' appears in more than one place in the RTL structure; in
  509.      other words, it is safe to do a tree-walk of all the insns in the
  510.      function and assume that each time a `label_ref' is seen it is
  511.      distinct from all others that are seen.
  512.  
  513.    * Only one `mem' object is normally created for each static variable or
  514.      stack slot, so these objects are frequently shared in all the places
  515.      they appear.  However, separate but equal objects for these variables
  516.      are occasionally made.
  517.  
  518.    * No RTL object appears in more than one place in the RTL structure
  519.      except as described above.  Many passes of the compiler rely on this
  520.      by assuming that they can modify RTL objects in place without unwanted
  521.      side-effects on other insns.
  522.  
  523.    * During initial RTL generation, shared structure is freely introduced. 
  524.      After all the RTL for a function has been generated, all shared
  525.      structure is copied by `unshare_all_rtl' in `emit-rtl.c', after which
  526.      the above rules are guaranteed to be followed.
  527.  
  528.    * During the combiner pass, shared structure with an insn can exist
  529.      temporarily.  However, the shared structure is copied before the
  530.      combiner is finished with the insn.  This is done by
  531.      `copy_substitutions' in `combine.c'.
  532.  
  533. File: internals,  Node: Machine Desc,  Next: Machine Macros,  Prev: RTL,  Up: Top
  534.  
  535. Machine Descriptions
  536. ********************
  537.  
  538. A machine description has two parts: a file of instruction patterns (`.md'
  539. file) and a C header file of macro definitions.
  540.  
  541. The `.md' file for a target machine contains a pattern for each instruction
  542. that the target machine supports (or at least each instruction that is
  543. worth telling the compiler about).  It may also contain comments.  A
  544. semicolon causes the rest of the line to be a comment, unless the semicolon
  545. is inside a quoted string.
  546.  
  547. See the next chapter for information on the C header file.
  548.  
  549. * Menu:
  550.  
  551. * Patterns::            How to write instruction patterns.
  552. * Example::             An explained example of a `define_insn' pattern.
  553. * RTL Template::        The RTL template defines what insns match a pattern.
  554. * Output Template::     The output template says how to make assembler code
  555.                           from such an insn.
  556. * Output Statement::    For more generality, write C code to output 
  557.                           the assembler code.
  558. * Constraints::         When not all operands are general operands.
  559. * Standard Names::      Names mark patterns to use for code generation.
  560. * Pattern Ordering::    When the order of patterns makes a difference.
  561. * Dependent Patterns::  Having one pattern may make you need another.
  562. * Jump Patterns::       Special considerations for patterns for jump insns.
  563. * Peephole Definitions::Defining machine-specific peephole optimizations.
  564. * Expander Definitions::Generating a sequence of several RTL insns
  565.                          for a standard operation.
  566.  
  567.  
  568. File: internals,  Node: Patterns,  Next: Example,  Prev: Machine Desc,  Up: Machine Desc
  569.  
  570. Everything about Instruction Patterns
  571. =====================================
  572.  
  573. Each instruction pattern contains an incomplete RTL expression, with pieces
  574. to be filled in later, operand constraints that restrict how the pieces can
  575. be filled in, and an output pattern or C code to generate the assembler
  576. output, all wrapped up in a `define_insn' expression.
  577.  
  578. A `define_insn' is an RTL expression containing four operands:
  579.  
  580.   1. An optional name.  The presence of a name indicate that this instruction
  581.      pattern can perform a certain standard job for the RTL-generation pass
  582.      of the compiler.  This pass knows certain names and will use the
  583.      instruction patterns with those names, if the names are defined in the
  584.      machine description.
  585.  
  586.      The absence of a name is indicated by writing an empty string where
  587.      the name should go.  Nameless instruction patterns are never used for
  588.      generating RTL code, but they may permit several simpler insns to be
  589.      combined later on.
  590.  
  591.      Names that are not thus known and used in RTL-generation have no
  592.      effect; they are equivalent to no name at all.
  593.  
  594.   2. The "RTL template" (*Note RTL Template::.) is a vector of incomplete RTL
  595.      expressions which show what the instruction should look like.  It is
  596.      incomplete because it may contain `match_operand' and `match_dup'
  597.      expressions that stand for operands of the instruction.
  598.  
  599.      If the vector has only one element, that element is what the
  600.      instruction should look like.  If the vector has multiple elements,
  601.      then the instruction looks like a `parallel' expression containing
  602.      that many elements as described.
  603.  
  604.   3. A condition.  This is a string which contains a C expression that is the
  605.      final test to decide whether an insn body matches this pattern.
  606.  
  607.      For a named pattern, the condition (if present) may not depend on the
  608.      data in the insn being matched, but only the target-machine-type
  609.      flags.  The compiler needs to test these conditions during
  610.      initialization in order to learn exactly which named instructions are
  611.      available in a particular run.
  612.  
  613.      For nameless patterns, the condition is applied only when matching an
  614.      individual insn, and only after the insn has matched the pattern's
  615.      recognition template.  The insn's operands may be found in the vector
  616.      `operands'.
  617.  
  618.   4. The "output template": a string that says how to output matching insns
  619.      as assembler code.  `%' in this string specifies where to substitute
  620.      the value of an operand.  *note Output Template::.
  621.  
  622.      When simple substitution isn't general enough, you can specify a piece
  623.      of C code to compute the output.  *note Output Statement::.
  624.  
  625. File: internals,  Node: Example,  Next: RTL Template,  Prev: Patterns,  Up: Machine Desc
  626.  
  627. Example of `define_insn'
  628. ========================
  629.  
  630. Here is an actual example of an instruction pattern, for the 68000/68020.
  631.  
  632.      (define_insn "tstsi"
  633.        [(set (cc0)
  634.              (match_operand:SI 0 "general_operand" "rm"))]
  635.        ""
  636.        "*
  637.      { if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
  638.          return \"tstl %0\";
  639.        return \"cmpl #0,%0\"; }")
  640.  
  641. This is an instruction that sets the condition codes based on the value of
  642. a general operand.  It has no condition, so any insn whose RTL description
  643. has the form shown may be handled according to this pattern.  The name
  644. `tstsi' means ``test a `SImode' value'' and tells the RTL generation pass
  645. that, when it is necessary to test such a value, an insn to do so can be
  646. constructed using this pattern.
  647.  
  648. The output control string is a piece of C code which chooses which output
  649. template to return based on the kind of operand and the specific type of
  650. CPU for which code is being generated.
  651.  
  652. `"rm"' is an operand constraint.  Its meaning is explained below.
  653.  
  654. File: internals,  Node: RTL Template,  Next: Output Template,  Prev: Example,  Up: Machine Desc
  655.  
  656. RTL Template for Generating and Recognizing Insns
  657. =================================================
  658.  
  659. The RTL template is used to define which insns match the particular pattern
  660. and how to find their operands.  For named patterns, the RTL template also
  661. says how to construct an insn from specified operands.
  662.  
  663. Construction involves substituting specified operands into a copy of the
  664. template.  Matching involves determining the values that serve as the
  665. operands in the insn being matched.  Both of these activities are
  666. controlled by special expression types that direct matching and
  667. substitution of the operands.
  668.  
  669. `(match_operand:M N TESTFN CONSTRAINT)'
  670.      This expression is a placeholder for operand number N of the insn. 
  671.      When constructing an insn, operand number N will be substituted at
  672.      this point.  When matching an insn, whatever appears at this position
  673.      in the insn will be taken as operand number N; but it must satisfy
  674.      TESTFN or this instruction pattern will not match at all.
  675.  
  676.      Operand numbers must be chosen consecutively counting from zero in
  677.      each instruction pattern.  There may be only one `match_operand'
  678.      expression in the pattern for each expression number, and they must
  679.      appear in order of increasing expression number.
  680.  
  681.      TESTFN is a string that is the name of a C function that accepts two
  682.      arguments, a machine mode and an expression.  During matching, the
  683.      function will be called with M as the mode argument and the putative
  684.      operand as the other argument.  If it returns zero, this instruction
  685.      pattern fails to match.  TESTFN may be an empty string; then it means
  686.      no test is to be done on the operand.
  687.  
  688.      Most often, TESTFN is `"general_operand"'.  It checks that the
  689.      putative operand is either a constant, a register or a memory
  690.      reference, and that it is valid for mode M.
  691.  
  692.      For an operand that must be a register, TESTFN should be
  693.      `"register_operand"'.  This prevents GNU CC from creating insns that
  694.      have memory references in these operands, insns which would only have
  695.      to be taken apart in the reload pass.
  696.  
  697.      For an operand that must be a constant, either TESTFN should be
  698.      `"immediate_operand"', or the instruction pattern's extra condition
  699.      should check for constants, or both.
  700.  
  701.      CONSTRAINT is explained later (*Note Constraints::.).
  702.  
  703. `(match_dup N)'
  704.      This expression is also a placeholder for operand number N.  It is
  705.      used when the operand needs to appear more than once in the insn.
  706.  
  707.      In construction, `match_dup' behaves exactly like `match_operand': the
  708.      operand is substituted into the insn being constructed.  But in
  709.      matching, `match_dup' behaves differently.  It assumes that operand
  710.      number N has already been determined by a `match_operand' appearing
  711.      earlier in the recognition template, and it matches only an
  712.      identical-looking expression.
  713.  
  714. `(address (match_operand:M N "address_operand" ""))'
  715.      This complex of expressions is a placeholder for an operand number N
  716.      in a ``load address'' instruction: an operand which specifies a memory
  717.      location in the usual way, but for which the actual operand value used
  718.      is the address of the location, not the contents of the location.
  719.  
  720.      `address' expressions never appear in RTL code, only in machine
  721.      descriptions.  And they are used only in machine descriptions that do
  722.      not use the operand constraint feature.  When operand constraints are
  723.      in use, the letter `p' in the constraint serves this purpose.
  724.  
  725.      M is the machine mode of the *memory location being addressed*, not
  726.      the machine mode of the address itself.  That mode is always the same
  727.      on a given target machine (it is `Pmode', which normally is `SImode'),
  728.      so there is no point in mentioning it; thus, no machine mode is
  729.      written in the `address' expression.  If some day support is added for
  730.      machines in which addresses of different kinds of objects appear
  731.      differently or are used differently (such as the PDP-10), different
  732.      formats would perhaps need different machine modes and these modes
  733.      might be written in the `address' expression.
  734.  
  735. File: internals,  Node: Output Template,  Next: Output Statement,  Prev: RTL Template,  Up: Machine Desc
  736.  
  737. Output Templates and Operand Substitution
  738. =========================================
  739.  
  740. The "output template" is a string which specifies how to output the
  741. assembler code for an instruction pattern.  Most of the template is a fixed
  742. string which is output literally.  The character `%' is used to specify
  743. where to substitute an operand; it can also be used to identify places
  744. different variants of the assembler require different syntax.
  745.  
  746. In the simplest case, a `%' followed by a digit N says to output operand N
  747. at that point in the string.
  748.  
  749. `%' followed by a letter and a digit says to output an operand in an
  750. alternate fashion.  Four letters have standard, built-in meanings described
  751. below.  The machine description macro `PRINT_OPERAND' can define additional
  752. letters with nonstandard meanings.
  753.  
  754. `%cDIGIT' can be used to substitute an operand that is a constant value
  755. without the syntax that normally indicates an immediate operand.
  756.  
  757. `%nDIGIT' is like `%cDIGIT' except that the value of the constant is
  758. negated before printing.
  759.  
  760. `%aDIGIT' can be used to substitute an operand as if it were a memory
  761. reference, with the actual operand treated as the address.  This may be
  762. useful when outputting a ``load address'' instruction, because often the
  763. assembler syntax for such an instruction requires you to write the operand
  764. as if it were a memory reference.
  765.  
  766. `%lDIGIT' is used to substitute a `label_ref' into a jump instruction.
  767.  
  768. `%' followed by a punctuation character specifies a substitution that does
  769. not use an operand.  Only one case is standard: `%%' outputs a `%' into the
  770. assembler code.  Other nonstandard cases can be defined in the
  771. `PRINT_OPERAND' macro.
  772.  
  773. The template may generate multiple assembler instructions.  Write the text
  774. for the instructions, with `\;' between them.
  775.  
  776. When the RTL contains two operand which are required by constraint to match
  777. each other, the output template must refer only to the lower-numbered
  778. operand.  Matching operands are not always identical, and the rest of the
  779. compiler arranges to put the proper RTL expression for printing into the
  780. lower-numbered operand.
  781.  
  782. One use of nonstandard letters or punctuation following `%' is to
  783. distinguish between different assembler languages for the same machine; for
  784. example, Motorola syntax versus MIT syntax for the 68000.  Motorola syntax
  785. requires periods in most opcode names, while MIT syntax does not.  For
  786. example, the opcode `movel' in MIT syntax is `move.l' in Motorola syntax. 
  787. The same file of patterns is used for both kinds of output syntax, but the
  788. character sequence `%.' is used in each place where Motorola syntax wants a
  789. period.  The `PRINT_OPERAND' macro for Motorola syntax defines the sequence
  790. to output a period; the macro for MIT syntax defines it to do nothing.
  791.  
  792. File: internals,  Node: Output Statement,  Next: Constraints,  Prev: Output Template,  Up: Machine Desc
  793.  
  794. C Statements for Generating Assembler Output
  795. ============================================
  796.  
  797. Often a single fixed template string cannot produce correct and efficient
  798. assembler code for all the cases that are recognized by a single
  799. instruction pattern.  For example, the opcodes may depend on the kinds of
  800. operands; or some unfortunate combinations of operands may require extra
  801. machine instructions.
  802.  
  803. If the output control string starts with a `*', then it is not an output
  804. template but rather a piece of C program that should compute a template. 
  805. It should execute a `return' statement to return the template-string you
  806. want.  Most such templates use C string literals, which require doublequote
  807. characters to delimit them.  To include these doublequote characters in the
  808. string, prefix each one with `\'.
  809.  
  810. The operands may be found in the array `operands', whose C data type is
  811. `rtx []'.
  812.  
  813. It is possible to output an assembler instruction and then go on to output
  814. or compute more of them, using the subroutine `output_asm_insn'.  This
  815. receives two arguments: a template-string and a vector of operands.  The
  816. vector may be `operands', or it may be another array of `rtx' that you
  817. declare locally and initialize yourself.
  818.  
  819. When an insn pattern has multiple alternatives in its constraints, often
  820. the appearance of the assembler code determined mostly by which alternative
  821. was matched.  When this is so, the C code can test the variable
  822. `which_alternative', which is the ordinal number of the alternative that
  823. was actually satisfied (0 for the first, 1 for the second alternative, etc.).
  824.  
  825. For example, suppose there are two opcodes for storing zero, `clrreg' for
  826. registers and `clrmem' for memory locations.  Here is how a pattern could
  827. use `which_alternative' to choose between them:
  828.  
  829.      (define_insn ""
  830.        [(set (match_operand:SI 0 "general_operand" "r,m")
  831.              (const_int 0))]
  832.        ""
  833.        "*
  834.        return (which_alternative == 0
  835.                ? \"clrreg %0\" : \"clrmem %0\");
  836.        ")
  837.  
  838. File: internals,  Node: Constraints,  Next: Standard Names,  Prev: Output Statement,  Up: Machine Desc
  839.  
  840. Operand Constraints
  841. ===================
  842.  
  843. Each `match_operand' in an instruction pattern can specify a constraint for
  844. the type of operands allowed.  Constraints can say whether an operand may
  845. be in a register, and which kinds of register; whether the operand can be a
  846. memory reference, and which kinds of address; whether the operand may be an
  847. immediate constant, and which possible values it may have.  Constraints can
  848. also require two operands to match.
  849.  
  850. * Menu:
  851.  
  852. * Simple Constraints::  Basic use of constraints.
  853. * Multi-Alternative::   When an insn has two alternative constraint-patterns.
  854. * Class Preferences::   Constraints guide which hard register to put things in.
  855. * Modifiers::           More precise control over effects of constraints.
  856. * No Constraints::      Describing a clean machine without constraints.
  857.  
  858.  
  859. File: internals,  Node: Simple Constraints,  Next: Multi-Alternative,  Prev: Constraints,  Up: Constraints
  860.  
  861. Simple Constraints
  862. ------------------
  863.  
  864. The simplest kind of constraint is a string full of letters, each of which
  865. describes one kind of operand that is permitted.  Here are the letters that
  866. are allowed:
  867.  
  868. `m'
  869.      A memory operand is allowed, with any kind of address that the machine
  870.      supports in general.
  871.  
  872. `o'
  873.      A memory operand is allowed, but only if the address is "offsetable". 
  874.      This means that adding a small integer (actually, the width in bytes
  875.      of the operand, as determined by its machine mode) may be added to the
  876.      address and the result is also a valid memory address.
  877.  
  878.      For example, an address which is constant is offsetable; so is an
  879.      address that is the sum of a register and a constant (as long as a
  880.      slightly larger constant is also within the range of address-offsets
  881.      supported by the machine); but an autoincrement or autodecrement
  882.      address is not offsetable.  More complicated indirect/indexed
  883.      addresses may or may not be offsetable depending on the other
  884.      addressing modes that the machine supports.
  885.  
  886.      Note that in an output operand which can be matched by another
  887.      operand, the constraint letter `o' is valid only when accompanied by
  888.      both `<' (if the target machine has predecrement addressing) and `>'
  889.      (if the target machine has preincrement addressing).
  890.  
  891. `<'
  892.      A memory operand with autodecrement addressing (either predecrement or
  893.      postdecrement) is allowed.
  894.  
  895. `>'
  896.      A memory operand with autoincrement addressing (either preincrement or
  897.      postincrement) is allowed.
  898.  
  899. `r'
  900.      A register operand is allowed provided that it is in a general register.
  901.  
  902. `d', `a', `f', ...
  903.       Other letters can be defined in machine-dependent fashion to stand for
  904.      particular classes of registers.  `d', `a' and `f' are defined on the
  905.      68000/68020 to stand for data, address and floating point registers.
  906.  
  907. `i'
  908.      An immediate integer operand (one with constant value) is allowed. 
  909.      This includes symbolic constants whose values will be known only at
  910.      assembly time.
  911.  
  912. `n'
  913.      An immediate integer operand with a known numeric value is allowed. 
  914.      Many systems cannot support assembly-time constants for operands less
  915.      than a word wide.  Constraints for these operands should use `n'
  916.      rather than `i'.
  917.  
  918. `I', `J', `K', ...
  919.       Other letters in the range `I' through `M' may be defined in a
  920.      machine-dependent fashion to permit immediate integer operands with
  921.      explicit integer values in specified ranges.  For example, on the
  922.      68000, `I' is defined to stand for the range of values 1 to 8.  This
  923.      is the range permitted as a shift count in the shift instructions.
  924.  
  925. `F'
  926.      An immediate floating operand (expression code `const_double') is
  927.      allowed.
  928.  
  929. `G', `H'
  930.      `G' and `H' may be defined in a machine-dependent fashion to permit
  931.      immediate floating operands in particular ranges of values.
  932.  
  933. `s'
  934.      An immediate integer operand whose value is not an explicit integer is
  935.      allowed.
  936.  
  937.      This might appear strange; if an insn allows a constant operand with a
  938.      value not known at compile time, it certainly must allow any known
  939.      value.  So why use `s' instead of `i'?  Sometimes it allows better
  940.      code to be generated.
  941.  
  942.      For example, on the 68000 in a fullword instruction it is possible to
  943.      use an immediate operand; but if the immediate value is between -32
  944.      and 31, better code results from loading the value into a register and
  945.      using the register.  This is because the load into the register can be
  946.      done with a `moveq' instruction.  We arrange for this to happen by
  947.      defining the letter `K' to mean ``any integer outside the range -32 to
  948.      31'', and then specifying `Ks' in the operand constraints.
  949.  
  950. `g'
  951.      Any register, memory or immediate integer operand is allowed, except
  952.      for registers that are not general registers.
  953.  
  954. `N' (a digit)
  955.      An operand that matches operand number N is allowed.  If a digit is
  956.      used together with letters, the digit should come last.
  957.  
  958.      This is called a "matching constraint" and what it really means is
  959.      that the assembler has only a single operand that fills two roles
  960.      considered separate in the RTL insn.  For example, an add insn has two
  961.      input operands and one output operand in the RTL, but on most machines
  962.      an add instruction really has only two operands, one of them an
  963.      input-output operand.
  964.  
  965.      Matching constraints work only in circumstances like that add insn. 
  966.      More precisely, the matching constraint must appear in an input-only
  967.      operand and the operand that it matches must be an output-only operand
  968.      with a lower number.
  969.  
  970.      For operands to match in a particular case usually means that they are
  971.      identical-looking RTL expressions.  But in a few special cases
  972.      specific kinds of dissimilarity are allowed.  For example, `*x' as an
  973.      input operand will match `*x++' as an output operand.  For proper
  974.      results in such cases, the output template should always use the
  975.      output-operand's number when printing the operand.
  976.  
  977. `p'
  978.      An operand that is a valid memory address is allowed.  This is for
  979.      ``load address'' and ``push address'' instructions.
  980.  
  981.      If `p' is used in the constraint, the test-function in the
  982.      `match_operand' must be `address_operand'.
  983.  
  984. In order to have valid assembler code, each operand must satisfy its
  985. constraint.  But a failure to do so does not prevent the pattern from
  986. applying to an insn.  Instead, it directs the compiler to modify the code
  987. so that the constraint will be satisfied.  Usually this is done by copying
  988. an operand into a register.
  989.  
  990. Contrast, therefore, the two instruction patterns that follow:
  991.  
  992.      (define_insn ""
  993.        [(set (match_operand:SI 0 "general_operand" "r")
  994.              (plus:SI (match_dup 0)
  995.                       (match_operand:SI 1 "general_operand" "r")))]
  996.        ""
  997.        "...")
  998.  
  999. which has two operands, one of which must appear in two places, and
  1000.  
  1001.      (define_insn ""
  1002.        [(set (match_operand:SI 0 "general_operand" "r")
  1003.              (plus:SI (match_operand:SI 1 "general_operand" "0")
  1004.                       (match_operand:SI 2 "general_operand" "r")))]
  1005.        ""
  1006.        "...")
  1007.  
  1008. which has three operands, two of which are required by a constraint to be
  1009. identical.  If we are considering an insn of the form
  1010.  
  1011.      (insn N PREV NEXT
  1012.        (set (reg:SI 3)
  1013.             (plus:SI (reg:SI 6) (reg:SI 109)))
  1014.        ...)
  1015.  
  1016. the first pattern would not apply at all, because this insn does not
  1017. contain two identical subexpressions in the right place.  The pattern would
  1018. say, ``That does not look like an add instruction; try other patterns.''
  1019. The second pattern would say, ``Yes, that's an add instruction, but there
  1020. is something wrong with it.''  It would direct the reload pass of the
  1021. compiler to generate additional insns to make the constraint true.  The
  1022. results might look like this:
  1023.  
  1024.      (insn N2 PREV N
  1025.        (set (reg:SI 3) (reg:SI 6))
  1026.        ...)
  1027.      
  1028.      (insn N N2 NEXT
  1029.        (set (reg:SI 3)
  1030.             (plus:SI (reg:SI 3) (reg:SI 109)))
  1031.        ...)
  1032.  
  1033. Because insns that don't fit the constraints are fixed up by loading
  1034. operands into registers, every instruction pattern's constraints must
  1035. permit the case where all the operands are in registers.  It need not
  1036. permit all classes of registers; the compiler knows how to copy registers
  1037. into other registers of the proper class in order to make an instruction
  1038. valid.  But if no registers are permitted, the compiler will be stymied: it
  1039. does not know how to save a register in memory in order to make an
  1040. instruction valid.  Instruction patterns that reject registers can be made
  1041. valid by attaching a condition-expression that refuses to match an insn at
  1042. all if the crucial operand is a register.
  1043.  
  1044.